﻿namespace Framework.ObjectPool
{
    /// <summary>
    /// 对象池接口
    /// </summary>
    public interface IObjectPool<T> where T : ObjectBase
    {
        /// <summary>
        /// 获取对象池的名称
        /// </summary>
        string Name
        {
            get;
        }
        /// <summary>
        /// 获取对象池中所有对象数量
        /// </summary>
        int Count
        {
            get;
        }
        /// <summary>
        /// 获取对象池中可以释放的对象数量
        /// </summary>
        int CanReleaseCount
        {
            get;
        }
        /// <summary>
        /// 获取或设置对象池自动释放可释放对象的间隔秒数
        /// </summary>
        float AutoReleaseInterval
        {
            get;
            set;
        }
        /// <summary>
        /// 获取或设置对象池中对象过期描述
        /// </summary>
        float ExpireTime
        {
            get;
            set;
        }
        /// <summary>
        /// 获取或设置对象池的容量
        /// </summary>
        int Capacity
        {
            get;
            set;
        }
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns>创建的对象</returns>
        T Spawn();
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <param name="name">要创建的对象的名称</param>
        /// <returns>创建的对象</returns>
        T Spawn(string name);
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <param name="packageName">对象所在资源包名称</param>
        /// <param name="resName">资源名称</param>
        /// <returns>创建的对象</returns>
        T Spawn(string packageName, string resName);
        /// <summary>
        /// 注册对象到对象池中
        /// </summary>
        /// <param name="obj">要注册的对象</param>
        void Register(T obj);
        /// <summary>
        /// 回收对象
        /// </summary>
        /// <param name="obj">要回收的内部对象</param>
        void Collect(T obj);
        /// <summary>
        /// 回收对象
        /// </summary>
        /// <param name="obj">要回收的对象</param>
        void Collect(object obj);
        /// <summary>
        /// 释放所有的空闲对象
        /// </summary>
        void ReleaseFreeObject();
        /// <summary>
        /// 释放所有对象
        /// </summary>
        void ReleaseAllObject();
    }
}
